package com.nav.backend.controller;

import com.nav.backend.pojo.CollectionLocation;
import com.nav.backend.pojo.CollectionPath;
import com.nav.backend.pojo.User;
import com.nav.backend.service.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;

import java.util.List;

/**
 * CollectionController 收藏控制器类，处理与收藏相关的请求
 *
 * @author xiukira
 */
@RestController
@RequestMapping("/collections")
public class CollectionController {
    @Autowired
    private CollectionService collectionService;

    /**
     * 获取所有收藏路径
     *
     * @return 所有收藏路径列表
     */
    @GetMapping("/path/listAll")
    public List<CollectionPath> pathListAll(@RequestParam String account) {
        System.out.println("调用获取所有收藏路径成功");
        List<CollectionPath> collectionPath = collectionService.pathListAll(account);
        for (CollectionPath cc : collectionPath) {
            System.out.println(cc.getCollection_path_origin());
            System.out.println(cc.getCollection_path_destination());
        }
        return collectionPath;
    }

    /**
     * 删除某一收藏路径
     *
     * @return 删除某一收藏路径的结果
     */
    @DeleteMapping("/path/delete")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public String pathDelete(@RequestBody CollectionPath collectionPath) {
        System.out.println("调用删除某一收藏路径接口成功");
        collectionService.pathDelete(collectionPath.getCollection_path_id());
        return "";
    }

    /**
     * 收藏路径
     *
     * @return 收藏路径结果
     */
    @PostMapping("/path/add")
    public String pathAdd(@RequestBody CollectionPath collectionPath) {
        System.out.println("调用收藏路径接口成功");
        collectionService.pathAdd(collectionPath.getCollection_path_origin(),
                collectionPath.getCollection_path_origin_x(),
                collectionPath.getCollection_path_origin_y(),
                collectionPath.getCollection_path_destination(),
                collectionPath.getCollection_path_destination_x(),
                collectionPath.getCollection_path_destination_y(),
                collectionPath.getCollection_path_info(),
                collectionPath.getDistance(),
                collectionPath.getTime(),
                collectionPath.getTree_line(),
                collectionPath.getMark(),
                collectionPath.getAccount()
        );
        return "";
    }

    /**
     * 获取所有收藏地点
     *
     * @return 所有收藏地点列表
     */
    @GetMapping("/poi/listAll")
    public List<CollectionLocation> poiListAll(@RequestParam String account) {
        System.out.println("调用获取所有收藏路径成功");
        List<CollectionLocation> collectionLocations = collectionService.poiListAll(account);
        for (CollectionLocation cc : collectionLocations) {
            System.out.println(cc.getCollection_location());
        }
        return collectionLocations;
    }

    /**
     * 收藏地点
     *
     * @return 收藏地点结果
     */
    @PostMapping("/poi/add")
    public String poiAdd(@RequestBody CollectionLocation collection_location) {
        System.out.println("调用收藏地点接口成功");
        System.out.println(collection_location.getCollection_location());
        collectionService.poiAdd(collection_location.getCollection_location(),
                collection_location.getCollection_location_x(),
                collection_location.getCollection_location_y(),
                collection_location.getCollection_location_info(),
                collection_location.getAccount()
        );
        return "";
    }

    /**
     * 删除某一收藏地点
     *
     * @return 删除某一收藏地点的结果
     */
    @DeleteMapping("/poi/delete")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public String poiDelete(@RequestBody CollectionLocation collectionLocation) {
        System.out.println("调用删除某一收藏地点接口成功");
        collectionService.poiDelete(collectionLocation.getCollection_location_id());
        return "";
    }

}
